/*
 * Copyright (c) 2022.版权所有高金磊
 */

package 领扣算法.A简单题.公平的糖果交换;

import java.util.Arrays;
import java.util.HashSet;

public class Main {
    public static void main(String arg[]){//main--来自高金磊

        new Main().fairCandySwap(new int[]{1,1}, new int[]{2,2});
    }

    public int[] fairCandySwap(int[] aliceSizes, int[] bobSizes) {
        int sum1=0;
        HashSet<Integer> data=new HashSet<>();
        for (int aliceSize : aliceSizes) {
            sum1+=aliceSize;
            data.add(aliceSize);
        }
        int sum2=Arrays.stream(bobSizes).sum();
        for (int bobSize : bobSizes) {
            if (data.contains((sum1-sum2+2*bobSize)/2)&&(sum1-sum2+2*bobSize)%2==0){
                return new int[]{(sum1-sum2+2*bobSize)/2,bobSize};
            }
        }

        return new int[]{-1,-1};
    }
}
